fix: handle missing dictionary batch for null-only columns in IPC reader#9623
Merged
alamb merged 4 commits intoapache:mainfrom Apr 8, 2026
Merged
fix: handle missing dictionary batch for null-only columns in IPC reader#9623alamb merged 4 commits intoapache:mainfrom
alamb merged 4 commits intoapache:mainfrom
Conversation
Per the IPC specification, dictionary batches may be omitted when all values in a dictionary-encoded column are null. The C++ implementation (Arrow C++ 17+) relies on this and does not emit a dictionary batch in such cases, which caused the Rust IPC reader to fail with: "Cannot find a dictionary batch with dict id: ..." When a dictionary batch is missing, synthesize an empty values array of the appropriate type so decoding can proceed.
Contributor
|
Looks like this was added to the spec 7 years ago: |
alamb
approved these changes
Apr 6, 2026
Contributor
alamb
left a comment
There was a problem hiding this comment.
Thank you for the contribution @joaquinhuigomez -- this looks good to me
I double checked that this matches the spec and that thsi was added to the spec 7 years ago in apache/arrow@0ddc1f4 / apache/arrow#5585
cc @pierrebelzile as the filer of
I also took the liberty of merging up from main and fixing clippy and fmt and simplifying the test a bit
| // Each message is: [continuation (4 bytes)] [meta_len (4 bytes)] | ||
| // [metadata (meta_len bytes)] [body (bodyLength bytes)] | ||
| let mut header = [0u8; 4]; | ||
| if std::io::Read::read_exact(&mut cursor, &mut header).is_err() { |
Contributor
There was a problem hiding this comment.
this is a strange way to write read_exact -- most other times I see it like
cursor.read_exact(&mut header).is_err() {
Contributor
There was a problem hiding this comment.
I took the liberty of pushing a commit to simplify it
Contributor
|
Thanks again @joaquinhuigomez |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
The IPC specification states:
Arrow C++ (v17+) relies on this and does not emit a dictionary batch when all values in a dictionary-encoded column are null. The Rust IPC reader currently fails with
"Cannot find a dictionary batch with dict id: ..."when reading such streams, making cross-language interop broken for this edge case.What changes are included in this PR?
When the IPC reader encounters a
Dictionary-typed column whosedict_idhas no corresponding entry indictionaries_by_id, it now synthesizes an empty values array of the appropriate type (vianew_empty_array) instead of returning an error. This matches the spec's allowance for omitted dictionary batches on null-only columns.Are these changes tested?
Yes. A new test (
test_read_null_dict_without_dictionary_batch) writes an IPC stream with an all-null dictionary column, strips the dictionary batch message from the raw bytes to simulate C++ behavior, then verifies the Rust reader successfully decodes the stream.Are there any user-facing changes?
IPC streams produced by C++ (or other implementations) that omit dictionary batches for null-only dictionary columns can now be read without error. Previously these streams caused a
ParseError.